package com.news.yp.baselibrary.navigationbottom;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.widget.ImageView;

import com.news.yp.baselibrary.R;

import me.panpf.sketch.Sketch;
import me.panpf.sketch.SketchImageView;

public class DefaultBottomTab extends BottomTabItem {

    private final BottomTabControler bottomTabControler;
    private BottomTabControler.Params P;

    public DefaultBottomTab(BottomTabControler.Params P) {
        super(R.layout.tab_bottom, P.mContext);
        this.P = P;
        bottomTabControler = new BottomTabControler();
    }

    @Override
    protected void initLayout() {
        SketchImageView imageView = findViewById(R.id.bottom_id);
        imageView.setImageResource(P.resId);
        imageView.getOptions().setDecodeGifImage(true);
        Sketch.with(P.mContext).displayFromResource(P.resId, imageView)
                .decodeGifImage()
                .commit();
    }

    @Override
    protected void setSelected(boolean selected) {

    }

    public static class Builder {
        private BottomTabControler.Params P;

        public Builder(Context context) {
            this(context, R.layout.tab_bottom);
        }

        public Builder(Context context, int resId) {
            P = new BottomTabControler.Params(context, resId);
        }


        public Builder resIcon(int resIconId) {
            P.resId = resIconId;
            return this;
        }

        public Builder setText(String text) {
            P.text = text;
            return this;
        }

        public DefaultBottomTab create() {
            DefaultBottomTab defaultBottomTab = new DefaultBottomTab(P);
            P.apply(defaultBottomTab.bottomTabControler);


            return defaultBottomTab;
        }
    }
}
